package com.dgshanger.sanhxiaofeisc.ui.person.purse

import android.annotation.SuppressLint
import android.support.v4.widget.SwipeRefreshLayout
import android.text.TextUtils
import android.view.View
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.entity.PurseEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.PurseContract
import com.dgshanger.sanhxiaofeisc.mvp.presenter.PursePresenter
import com.xx.baseuilibrary.mvp.lcec.BaseMvpLcecActivity
import kotlinx.android.synthetic.main.activity_purse.*


/**
 * PurseActivity
 * 沉迷学习不能自拔
 * Describe：钱包
 * Created by 雷小星🍀 on 2018/4/16 15:59.
 */
class PurseActivity : BaseMvpLcecActivity<SwipeRefreshLayout, PurseEntity, PurseContract.Model, PurseContract.View, PursePresenter>(),
        PurseContract.View {
    override fun setRefresh(b: Boolean) {
        contentView.post {
            contentView.isRefreshing = b
        }
    }

    override fun loadData(refresh: Boolean) {
        presenter.myWallet()
    }

    @SuppressLint("SetTextI18n")
    override fun setData(data: PurseEntity) {
        showContent()

        with(data) {
            tv_user_asset_total.text = user_asset_total
            tv_user_integral_total.text = user_integral_total
            tv_user_pending_asset_total.text = user_pending_asset_total
            tv_user_wallet_money.text = user_wallet_money

            //最近交易
            view_last_sale.visibility = if (TextUtils.isEmpty(new_pay_rcd?.shop_name)) View.GONE else View.VISIBLE
            view_empty.visibility = if (!TextUtils.isEmpty(new_pay_rcd?.shop_name)) View.GONE else View.VISIBLE
            tv_shop_name.text = new_pay_rcd?.shop_name
            tv_created_at.text = new_pay_rcd?.created_at
            tv_pay_remark.text = new_pay_rcd?.pay_remark
            tv_pay_wallet_money.text = "${getString(R.string.Cash)}:${new_pay_rcd?.pay_wallet_money}"
            tv_pay_integral.text = "${getString(R.string.integral)}:${new_pay_rcd?.pay_integral}"
        }
    }

    override fun initData() {
        super.initData()
        contentView.setColorSchemeResources(R.color.colorAccent)
    }

    override fun onResume() {
        super.onResume()
        loadData(true)
    }

    override fun createPresenter(): PursePresenter = PursePresenter()

    override fun getActivityLayoutId(): Int = R.layout.activity_purse

    override fun initEvent() {
        tv_bill_query.setOnClickListener {
            //账单查询
            startActivity(BillQueryActivity::class.java)
        }
        tv_transfer_accounts.setOnClickListener {
            //转账
            startActivity(TransferAccountsActivity::class.java)
        }

        tv_withdraw.setOnClickListener {
            //提现
            startActivity(WithdrawActivity::class.java)
        }
        tv_member_ship_card.setOnClickListener {
            //会员卡夹
            startActivity(MembershipCardActivity::class.java)
        }
        contentView.setOnRefreshListener {
            loadData(true)
        }
    }
}